<?php

require_once (JPATH_PLUGINS.DS.'content'.DS.'StatZone_BattingAve.php');

class HTML_statzone
{
function showSections($rows, $option)
{
?><table><?php
foreach($rows as $row)
{
$link = 'index.php?option=' .
$option . '&id=' . $row->id . '&task=view' .$row->name;
echo
'<tr>
<td>
<a href="' . $link . '">' . $row->name . '</a>
</td>
</tr>';
}
?></table><?php
}

function showPlayers($rows, $option, &$pageNav, &$lists)
{
echo '<div class="componentheading">Stat Zone - Players</div>';
?>
<form action="index.php?option=com_statzone&task=viewPlayers" method="post" name="adminForm">
<table>
    <tr>
        <td align="left" width="100%">
            <?php echo JText::_( 'Filter' ); ?>:
            <input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
            <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
            <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_provid').value='0';this.form.getElementById('filter_clubid').value='0';this.form.getElementById('filter_teamid').value='0';this.form.submit();"><?php echo JText::_( 'Filter Reset' ); ?></button>
        </td>
        <td nowrap="nowrap">
            <?php
            echo $lists['filter_provid'];
            echo $lists['filter_clubid'];
            echo $lists['filter_teamid'];
            ?>
        </td>
    </tr>
</table>

<table class="contentpane">
<thead>
    <tr>
        <th class="sectiontableheader">Player</th>
        <th class="sectiontableheader">Stats</th>
        <th class="sectiontableheader">Club</th>
        <th class="sectiontableheader">Province</th>
    </tr>
</thead>
<tfoot>
    <tr align="center">
        <td colspan="4">
            <?php echo $pageNav->getListFooter(); ?>
        </td>
    </tr>
</tfoot>
<tbody>
<?php
$k = 1;
foreach($rows as $row)
{

$linkStats = 'index.php?option=com_content&view=article&id=' . $row->contentid;
$linkGames = 'index.php?option=' .
$optionGames . '&id=' . $row->id . '&task=viewPlayerGames';
$linkClub = 'index.php?option=' .
$optionClub . '&id=' . $row->clubid . '&task=viewTeams';
echo
'<tr class="sectiontableentry'.$k.'">
<td> ' . $row->surname . ', '. $row->firstname . '</td>
<td align="center" >
<a href="' . $linkStats . '"><img src="images/statzone/stats.gif"></a>
</td>
<td>
<a href="' . $linkClub . '">' . $row->club . '</a>
</td>
<td>
' . $row->province . '
</td> 
</tr>
';
$k = 3 - $k;
}
?>
</tbody>
</table>

</form>
<?php
}

function showTeamPlayers($rows, $option, $teamName)
{

?><table class="contentpane"><?php
echo
'<tr>
<td colspan="2" class="sectiontableheader"> Team : ' . $teamName . '</td>
</tr>
';
$k = 1;
foreach($rows as $row)
{

$link = 'index.php?option=com_content&view=article&id=' . $row->contentid;
echo
'<tr class="sectiontableentry'.$k.'">
    <td><a href="' . $link . '">' . $row->surname . ', '.$row->firstname.'</a></td>
 </tr>';
$k = 3 - $k;
}
?></table><?php
}

function showTeamPlayerStats($rows, $twoDayStats, $seasonPlayersList, $option, $teamName)
{

?><table class="contentpane"><?php
echo
'
<tr>
<td colspan="2" class="sectiontableheader"> Team : ' . $teamName . '</td>
</tr>
<tr>

</tr>
<tr>

</tr>
<tr valign="top">
<td colspan="5">
<table class="contentpane">
<tr>
    <td colspan="6" class="sectiontableheader">Batting</td>
    <td colspan="7" class="sectiontableheader">Bowling</td>
</tr>
<tr>
<td width="15%" class="sectiontableheader"> </td>
<td width="8%" class="sectiontableheader">Game</td>
<td width="5%" class="sectiontableheader"> Inns</td>
<td width="8%" class="sectiontableheader"> Runs</td>
<td width="8%" class="sectiontableheader"> NO</td>
<td width="8%" class="sectiontableheader"> Ave</td>

<td width="8%" class="sectiontableheader"> Inns</td>
<td width="8%" class="sectiontableheader"> Overs</td>
<td width="8%" class="sectiontableheader"> Mdns</td>
<td width="8%" class="sectiontableheader"> Runs</td>
<td width="8%" class="sectiontableheader"> Wkts</td>
<td width="8%" class="sectiontableheader"> Ave</td>
<td width="8%" class="sectiontableheader"> Econ</td>
</tr>
';
$i=0;$k = 1;
foreach($seasonPlayersList as $seasonPlayer)
{

$row = $rows[$seasonPlayer->playerid];

$link = 'index.php?option=com_content&view=article&id=' . $row->contentid;
$batave = 0;
if($row->totaloutinnings==0) 
    $batave = $row->totalruns ;
else 
    $batave = $row->totalruns/$row->totaloutinnings;
    
$totalnotouts = $row->totalinnings - $row->totaloutinnings;
$batave = sprintf("%1\$.2f",$batave);

$bowlingecon = $row->bowl_totovers ==0 ? '' : $row->bowl_totruns / $row->bowl_totovers;
$bowlingecon =  $bowlingecon==''?'':sprintf("%1\$.2f",$bowlingecon);
$bowlingaverage = $row->bowl_totwickets==0?'': ($row->bowl_totruns)/$row->bowl_totwickets; 
$bowlingaverage =  $bowlingaverage==''?'':sprintf("%1\$.2f",$bowlingaverage);

//$player = array_search($row->playerid, $twoDayStats);

if($row->totalinnings !=0 || $row->bowl_totalinnings !=0){

	echo
	'<tr class="sectiontableentry'.$k.'">
	<td width="15%" >
	<a href="' . $link . '">'. $seasonPlayer->surname . ', ' . $seasonPlayer->firstname . '</a>
	</td>
	<td width="8%" >1 Day </td>  
	<td width="5%" > '. $row->totalinnings . '</td>
	<td width="8%" > '. $row->totalruns . '</td>
	<td width="8%" > '. $totalnotouts . '</td>
	<td width="8%" > '. $batave . '</td>
	<td width="8%" > '. $row->bowl_totalinnings . '</td>
	<td width="8%" > '. $row->bowl_totovers . '</td>
	<td width="8%" > '. $row->bowl_totmaidens . '</td>
	<td width="8%" > '. $row->bowl_totruns . '</td>
	<td width="8%" > '. $row->bowl_totwickets . '</td>
	<td width="8%" > '. $bowlingaverage . '</td>
	<td width="8%" > '. $bowlingecon . '</td>
	</tr>';
}


$playerTwoDayStat = $twoDayStats[$seasonPlayer->playerid];

$twoDayBatave = 0;
if($playerTwoDayStat->totaloutinnings==0) 
    $twoDayBatave = $playerTwoDayStat->totalruns ;
else 
    $twoDayBatave = $playerTwoDayStat->totalruns/$playerTwoDayStat->totaloutinnings;
    
$twoDayTotalnotouts = $playerTwoDayStat->totalinnings - $playerTwoDayStat->totaloutinnings;
$twoDayBatave = sprintf("%1\$.2f",$twoDayBatave);

$twoDayBowlingecon = $playerTwoDayStat->bowl_totovers ==0 ? '' : $playerTwoDayStat->bowl_totruns / $playerTwoDayStat->bowl_totovers;
$twoDayBowlingecon =  $twoDayBowlingecon==''?'':sprintf("%1\$.2f",$twoDayBowlingecon);
$twoDayBowlingaverage = $playerTwoDayStat->bowl_totwickets==0?'': ($playerTwoDayStat->bowl_totruns)/$playerTwoDayStat->bowl_totwickets; 
$twoDayBowlingaverage =  $twoDayBowlingaverage==''?'':sprintf("%1\$.2f",$twoDayBowlingaverage);

if($playerTwoDayStat->totalinnings !=0 || $playerTwoDayStat->bowl_totalinnings !=0){
	echo
	'<tr class="sectiontableentry'.$k.'">
	<td width="15%" >';

		if($row->totalinnings ==0 && $row->bowl_totalinnings ==0){
			echo'<a href="' . $link . '">'. $seasonPlayer->surname . ', ' . $seasonPlayer->firstname . '</a>';
		}	

	echo'
	</td>  
	<td width="8%" >2 Day </td>  
	<td width="5%" > '. $playerTwoDayStat->totalinnings . '</td>
	<td width="8%" > '. $playerTwoDayStat->totalruns . '</td>
	<td width="8%" > '. $twoDayTotalnotouts . '</td>
	<td width="8%" > '. $twoDayBatave . '</td>
	<td width="8%" > '. $playerTwoDayStat->bowl_totalinnings . '</td>
	<td width="8%" > '. $playerTwoDayStat->bowl_totovers . '</td>
	<td width="8%" > '. $playerTwoDayStat->bowl_totmaidens . '</td>
	<td width="8%" > '. $playerTwoDayStat->bowl_totruns . '</td>
	<td width="8%" > '. $playerTwoDayStat->bowl_totwickets . '</td>
	<td width="8%" > '. $twoDayBowlingaverage . '</td>
	<td width="8%" > '. $twoDayBowlingecon . '</td>
	</tr>';
}


$i++;
$k = 3 - $k;
}
echo'</table>
</td>
</tr>
';
?></table><?php
}

function showClubs($rows, $option, &$pageNav, &$lists)
{
echo '<div class="componentheading">Stat Zone - Clubs</div>';
?>
<form action="index.php?option=com_statzone&task=viewClubs" method="post" name="adminForm">
<table>
    <tr>
        <td align="left" width="100%">
            <?php echo JText::_( 'Filter' ); ?>:
            <input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
            <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
            <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_provid').value='0';this.form.getElementById('filter_clubid').value='0';this.form.getElementById('filter_teamid').value='0';this.form.submit();"><?php echo JText::_( 'Filter Reset' ); ?></button>
        </td>
        <td nowrap="nowrap">
            <?php
            echo $lists['filter_provid'];
            ?>
        </td>
    </tr>
</table>

<table class="contentpane">
<thead>
    <tr>
        <th class="sectiontableheader">Club</th>
        <th class="sectiontableheader">Club Teams</th>
        <th class="sectiontableheader">Province</th>
    </tr>
</thead>
<tfoot>
    <tr align="center">
        <td colspan="4">
            <?php echo $pageNav->getListFooter(); ?>
        </td>
    </tr>
</tfoot>
<tbody>
<?php
$k = 1;
foreach($rows as $row)
{

    $link = 'index.php?option=' .
    $option . '&id=' . $row->id . '&task=viewTeams';
    $clubArticlelink = 'index.php?option=com_content&view=article&id=' . $row->contentid;
    echo
    '<tr class="sectiontableentry'.$k.'">
        <td>
        <a href="' . $clubArticlelink . '">' . $row->title . '</a>
        </td> 
        <td>
        <a href="' . $link . '"><img src="images/statzone/stats.gif"></a>
        </td> 
        <td> ' . $row->name . '</td>
    </tr>';
    $k = 3 - $k;
}
?>
</tbody>
</table>
</form>
<?php
}

function showTeams($rows, $option)
{
echo '<div class="componentheading">Stat Zone - Teams</div>';
?><table class="contentpane">
<tr>
	<td class="sectiontableheader">
	Teams
	</td>
	<td class="sectiontableheader">
	Games
	</td>
	<td class="sectiontableheader">
	Stats
	</td>
	<td class="sectiontableheader">
	Players
	</td>
</tr>
<?php
foreach($rows as $row)
{

$linkGames = 'index.php?option=' .
$optionGames . '&id=' . $row->id . '&task=viewTeamGames&teamName=' . $row->name;
$linkStats = 'index.php?option=' .
$optionStats . '&id=' . $row->id . '&task=viewTeamPlayerStats&teamId='. $row->id . '&teamName=' . $row->name;
$linkPlayers = 'index.php?option=' .
$optionPlayers . '&id=' . $row->id . '&task=viewTeamPlayers&teamName=' . $row->name;
echo
'<tr>
<td> ' . $row->name . '</td>
<td align="center" >
	<a href="' . $linkGames . '"><img src="images/statzone/games.gif"></a>
</td> 
<td align="center" >
	<a href="' . $linkStats . '"><img src="images/statzone/stats.gif"></a>
</td> 
<td align="center" >
	<a href="' . $linkPlayers . '"><img src="images/statzone/player.gif"></a>
</td>
</tr>';
}
?></table><?php
}

function showScorecards($rows, $option, &$lists, &$pageNav)
{

?>
<form action="index.php?option=com_statzone&task=viewScorecards" method="post" name="adminForm">
<table>
    <tr>
        <td align="left" width="100%">
            <?php echo JText::_( 'Filter (season or team)' ); ?>:
            <input type="text" name="search" id="search" value="<?php echo $lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
            <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
            <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_provid').value='0';this.form.getElementById('filter_division').value='0';this.form.submit();"><?php echo JText::_( 'Filter Reset' ); ?></button>
        </td>
        <td nowrap="nowrap">
            <?php
            echo $lists['filter_provid'];
            echo $lists['filter_division'];
            ?>
        </td>
    </tr>
</table>

<table class="contentpane">
<thead>
    <tr>
    <th class="sectiontableheader">Date</th>
    <th class="sectiontableheader">Home Team</th>
    <th class="sectiontableheader">Away Team</th>
    <th class="sectiontableheader">Innings</th>
    <th class="sectiontableheader">Result</th>
    </tr>
</thead>    
<tfoot>
     <tr align="center">
        <td colspan="4">
            <?php echo $pageNav->getListFooter(); ?>
        </td>
    </tr>
</tfoot>
<tbody>
<?php
$k=1;
foreach($rows as $row)
{

$link = 'index.php?option=' .
$option . '&id=' . $row->id . '&task=viewScorecard';
echo
'<tr class="sectiontableentry'.$k.'">
<td>
<a href="' . $link . '">' . substr($row->firstinndate,0,10) . '<br>' .substr($row->secondinndate,0,10) . ' </a>
</td>
<td> ' . $row->hometeamname . '</td>
<td> ' . $row->awayteamname . '</td>
<td> ' . $row->inn . '</td>
<td> ' . $row->result . '</td>
</tr>';
$k = 3 - $k;
}
?>
</tbody>
</table>

</form>
<?php
}

function showScorecard($row, $statstable, $option)
{

?>

				<table class="contentpane">
				<tbody>
					<tr>
						<td width="20%" class="sectiontableheader">
							<label for="firstname">
								<?php echo JText::_( 'Season' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?php echo $row->season;?>
						</td>
                        <td width="20%" class="sectiontableheader">
							<label for="firstname">
								<?php echo JText::_( 'Division' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?php echo $row->division;?>
						</td>
                        <td width="20%" class="sectiontableheader">
							<label for="hometeamid">
								<?php echo JText::_( 'Club' ); ?>:
							</label>
						</td>
                        <td width="20%">
							<?php echo $row->hometeamname;?>
						</td>
                        <td width="20%" class="sectiontableheader">
							<label for="firstname">
								<?php echo JText::_( 'Opponent' ); ?>:
							</label>
						</td>
                        <td width="20%">
							<?php echo $row->awayteamname;?>
						</td>						
					</tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%" class="sectiontableheader">
							<label for="firstinndate">
								<?php echo JText::_( '1st Inn date' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?
                                $inndate = $row->firstinndate > '' ? date('Y-m-d',strtotime($row->firstinndate)) : '';
								echo($inndate);
                            ?>
						</td>
                    </tr>
                    <tr>
                        <td width="20%" class="sectiontableheader">
							<label for="secondinndate">
								<?php echo JText::_( '2nd Inn date' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?
                                $inndate2 = $row->secondinndate > '' ? date('Y-m-d',strtotime($row->secondinndate)) : '';
								echo($inndate2);
                            ?>
						</td>
                    </tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
                    <tr>
                        <td width="20%" class="sectiontableheader">
                            <?php echo JText::_( 'Scores' ); ?>:
                        </td>
                        <td class="sectiontableheader" width="20%">
                            <?php echo JText::_( 'Club' ); ?>
                        </td>
                        <td class="sectiontableheader" width="20%">
                            <?php echo JText::_( 'Opponent' ); ?>
                        </td>
					</tr>
                    <tr>
                        <td width="20%" class="sectiontableheader">
							<label for="club_firstinnrunswickets">
								<?php echo JText::_( '1st Inn (runs/wkts)' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?php echo $row->firstinnscore_home; ?>
						</td>
                        <td width="20%">
							<?php echo $row->firstinnscore_opponent; ?>
						</td>
                    </tr>
                    <tr>
                        <td width="20%" class="sectiontableheader">
							<label for="club_secondinnrunswickets">
								<?php echo JText::_( '2nd Inn (runs/wkts)' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?php echo $row->secondinnscore_home; ?>
						</td>
                        <td width="20%">
							<?php echo $row->secondinnscore_opponent; ?>
						</td>
                    </tr>
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>    
                    <tr>
						<td width="20%" class="sectiontableheader">
							<label for="result">
								<?php echo JText::_( 'Result' ); ?>:
							</label>
						</td>
						<td width="20%">
                           <?php echo $row->result; ?>
							
						</td>
                        <td width="20%" class="sectiontableheader">
							<label for="resultdetails">
								<?php echo JText::_( 'By' ); ?>:
							</label>
						</td>
						<td width="20%">
							<?php echo $row->resultdetails; ?>
						</td>
					</tr>			
                    <tr>
						<td width="20%" >
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
                        <td width="20%">
							
						</td>
						<td width="20%">
								<?php echo ' '; ?>
						</td>
					</tr>
				</tbody>
				</table>

<?php
echo $statstable;
?><?php
}

function showPlayer($rows, $option)
{

?><table><?php
foreach($rows as $row)
{

$link = 'index.php?option=' .
$option . '&id=' . $row->id . '&task=view';
echo
'<tr>
<td>
' . $row->firstname . '
</td> 
<td> ' . $row->idnumber . '</td>
</tr>';
}

?></table>
<?php
}
function showTeamGames($oneDayGamesRows, $twoDayGamesRows, $option, $teamName)
{
?><table class="contentpane">
<?php
echo
'<tr>
<td class="sectiontableheader"> Team : ' . $teamName . '</td>
</tr>
'
?>
<tr>
<td colspan="7">&nbsp;</td>
</tr>
<tr>
<td class="sectiontableheader" colspan="7">One Day Games</td>
</tr>
<tr>
<td colspan="7">&nbsp;</td>
</tr>
<tr>
<td class="sectiontableheader"></td>
<td class="sectiontableheader">
	Date
</td> 
<td class="sectiontableheader">
	Opponent
</td>
<td class="sectiontableheader">
	Div
</td>
<td class="sectiontableheader">
	Score
</td>
<td class="sectiontableheader">
	Winner
</td>
<td class="sectiontableheader">
	Won By
</td>
</tr>
<?php
foreach($oneDayGamesRows as $oneDayGamesRow)
{

$link = 'index.php?option=' .
$option . '&id=' . $oneDayGamesRow->scorecardId . '&task=viewScorecard';
echo
'<tr>
<td align="center" ><a href="' . $link . '"><img src="images/statzone/stats.gif"></a></td>
<td>
' . substr($oneDayGamesRow->firstinndate,8,2) .'-'. substr($oneDayGamesRow->firstinndate,5,2) .'-'. substr($oneDayGamesRow->firstinndate,0,4). '
</td> 
<td> ' . $oneDayGamesRow->opponent . '</td>
<td> ' . $oneDayGamesRow->division . '</td>
<td> ' . $oneDayGamesRow->result . '</td>
<td> ' . $oneDayGamesRow->winningteam . '</td>
<td> ' . $oneDayGamesRow->resultdetails . '</td>
</tr>';
}
?>
<tr>
<td colspan="7">&nbsp;</td>
</tr>
<tr>
<td class="sectiontableheader" colspan="7">Two Day Games</td>
</tr>
<tr>
<td colspan="7">&nbsp;</td>
</tr>
<tr>
<td class="sectiontableheader"></td>
<td class="sectiontableheader">
	Date
</td> 
<td class="sectiontableheader">
	Opponent
</td>
<td class="sectiontableheader">
	Div
</td>
<td class="sectiontableheader">
	Score
</td>
<td class="sectiontableheader">
	Winner
</td>
<td class="sectiontableheader">
	Won By
</td>
<?php
foreach($twoDayGamesRows as $twoDayGamesRow)
{

$link = 'index.php?option=' .
$option . '&id=' . $twoDayGamesRow->scorecardId . '&task=viewScorecard';
echo
'<tr>
<td align="center" ><a href="' . $link . '"><img src="images/statzone/stats.gif"></a></td>
<td>
' . substr($twoDayGamesRow->firstinndate,0,10) . '
</td> 
<td> ' . $twoDayGamesRow->opponent . '</td>
<td> ' . $twoDayGamesRow->division . '</td>
<td> ' . $twoDayGamesRow->result . '</td>
<td> ' . $twoDayGamesRow->winningteam . '</td>
<td> ' . $twoDayGamesRow->resultdetails . '</td>
</tr>';
}
?></table>
<?php
}

function showTeamStats($rows, $option)
{

?><table><?php
foreach($rows as $row)
{

$link = 'index.php?option=' .
$option . '&id=' . $row->id . '&task=view';
echo
'<tr>
<td>
' . $row->firstname . '
</td> 
<td> ' . $row->idnumber . '</td>
</tr>';
}
?></table><?php
}

function showPlayer2($row, $option)
{echo $row->id;
?>
<p class="contentheading"><?php echo $row->firstname; ?></p>
<p><strong>FirstName:</strong> <?php echo $row->firstname; ?></p>
<p><strong>Surname:</strong> <?php echo $row->surname; ?></p>
<?php $link = 'index.php?option=' . $option ; ?>
<a href="<?php echo $link; ?>">&lt; return to the reviews</a>
<?php
}
}

